package com.archstoday.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.archstoday.R;
import com.archstoday.entity.CommentToEntity;
import com.archstoday.utils.ToolUtils;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 用户评论页面列表适配器-回复我的
 */
public class CommentToMeAdapter extends BaseAdapter {

    private Context mContext;
    private List<CommentToEntity.DataBean> mData;

    public CommentToMeAdapter(Context context) {
        mContext = context;
    }

    public void setData(List<CommentToEntity.DataBean> data) {
        mData = data;
        notifyDataSetChanged();
    }

    public void addDat(List<CommentToEntity.DataBean> data) {
        mData.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (mData == null) {
            return 0;
        }
        return mData.size();
    }

    @Override
    public CommentToEntity.DataBean getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder;
        if (view == null) {
            holder = new Holder();
            view = LayoutInflater.from(mContext).inflate(R.layout.item_comment_to_me, null);
            holder.userHead = (CircleImageView) view.findViewById(R.id.item_user_head);
            holder.userName = (TextView) view.findViewById(R.id.item_user_name_tv);
            holder.userTime = (TextView) view.findViewById(R.id.item_user_time_tv);
            holder.userComment = (TextView) view.findViewById(R.id.item_user_comment_tv);
            holder.myHead = (CircleImageView) view.findViewById(R.id.item_my_head);
            holder.myName = (TextView) view.findViewById(R.id.item_my_name_tv);
            holder.myTime = (TextView) view.findViewById(R.id.item_my_time_tv);
            holder.myComment = (TextView) view.findViewById(R.id.item_my_comment_tv);

            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }

        holder.userName.setText(mData.get(i).getReply().getUserName());
        holder.userTime.setText(ToolUtils.getCreatTime
                (String.valueOf(mData.get(i).getReply().getCreateTime())));
        holder.userComment.setText(mData.get(i).getReply().getCommentText());
        holder.myName.setText(mData.get(i).getRootComment().getUserName());
        holder.myTime.setText(ToolUtils.getCreatTime
                (String.valueOf(mData.get(i).getRootComment().getCreateTime())));
        holder.myComment.setText(mData.get(i).getRootComment().getCommentText());

        return view;
    }

    class Holder {
        CircleImageView userHead, myHead;
        TextView userName, userTime, userComment;
        TextView myName, myTime, myComment;
    }
}